package com.kamistoat.ruoyi.ruoyiapisystem.factory;

import com.kamistoat.ruoyi.ruoyiapisystem.domain.SysLogininfor;
import com.kamistoat.ruoyi.ruoyiapisystem.domain.SysOperLog;
import com.kamistoat.ruoyi.ruoyiapisystem.feign.RemoteLogService;
import com.kamistoat.ruoyi.ruoyicommoncore.domain.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 日志服务的降流处理
 */
@Component
public class RemoteLogFallbackFactory implements FallbackFactory<RemoteLogService> {

    private static final Logger LOGGER = LoggerFactory.getLogger(RemoteLogFallbackFactory.class);

    @Override
    public RemoteLogService create(Throwable cause) {
        LOGGER.error("日志服务调用失败:{}", cause.getMessage());
        return new RemoteLogService() {
            @Override
            public R<Boolean> saveLog(SysOperLog sysOperLog, String source) {
                return R.fail("日志服务调用失败:" + cause.getMessage());
            }

            @Override
            public R<Boolean> saveLogininfor(SysLogininfor sysLogininfor, String source) {
                return R.fail("日志服务调用失败:" + cause.getMessage());
            }
        };
    }
}
